﻿/*include:js\declare*/
//输入框输入长度控件	<input inputlength="{Length:500,SkinId:'YYY',ErrorSkinId:'ZZZ'}" id="XXX" /><div id="YYY" SKIN="true" style="display:none">还可以输入=@InputLength字</div><div id="ZZZ" SKIN="true" style="display:none">已经超出=@InputLength字</div>
(function(){
var InputLength=function()
	{
	this.GetArgument(arguments[0],{Id:null,Event:null,Length:0,SkinId:null,LengthName:'InputLength',SkinView:{},ErrorSkinId:null,ErrorLengthName:'InputLength',ErrorSkinView:{}});
	this.Start(this.Event||{IsGetOnly:1});
	};
(fastCSharp.Functions.InputLength=InputLength).Inherit(fastCSharp.BaseFunction,{
Start:function(Event)
	{
	if(!Event.IsGetOnly)
		{
		var Element=fastCSharp.$Id(this.Id),Input=Element.Element();
		if(Input!=this.Element)
			{
			this.Element=Input;
			Element.AddEvent('keypress,keyup,blur',fastCSharp.ThisFunction(this,this.Check));
			}
		}
	},
Check:function()
	{
	var Length=fastCSharp.$Value(this.Id).length;
	if(Length<=this.Length)
		{
		if(this.ErrorSkinId)	fastCSharp.Skins[this.ErrorSkinId].Hide();
		if(this.SkinId)
			{
			var Value=this.SkinView||{};
			Value[this.LengthName]=this.Length-Length;
			fastCSharp.Skins[this.SkinId].Show(Value);
			}
		}
	else	{
		if(this.SkinId)	fastCSharp.Skins[this.SkinId].Hide();
		if(this.ErrorSkinId)
			{
			var Value=this.ErrorSKinView||{};
			Value[this.ErrorLengthName]=Length-this.Length;
			fastCSharp.Skins[this.ErrorSkinId].Show(Value);
			}
		}
	},
GetValue:function()
	{
	var Value=fastCSharp.$Value(this.Id);
	return Value.length<=this.Length?Value:null;
	}
		});
new fastCSharp.Declare('InputLength','focus','Src');
})();